package cn.antblog.poi.ppt;

import org.apache.commons.io.FileUtils;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFPictureData;
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;

/**
 * @author YangJingyi
 * @date 2021-12-06 15:52
 */
public class Test1 {


    public static void main(String[] args)throws Exception {
        Test1 test1 = new Test1();
        InputStream inputStream = GenerateTempPpt.readTemplateInput();
        XMLSlideShow xmlSlideShow = GenerateTempPpt.convertPPtx(inputStream);
        XMLSlideShow xmlSlideShow1 = test1.analysePPTX(xmlSlideShow);
        xmlSlideShow1.write(new FileOutputStream("C:\\Users\\YangJingyi\\Desktop\\kd2.pptx"));

    }
    private XMLSlideShow analysePPTX(XMLSlideShow xmlSlideShow) throws Exception {
        //获取所有的幻灯片
        List<XSLFSlide> slides = xmlSlideShow.getSlides();
        for (XSLFSlide slide : slides) {
            byte[] bt2 = FileUtils.readFileToByteArray(new File("C:\\Users\\YangJingyi\\Desktop\\ppt\\abc.png"));
            //添加图片 到 当前幻灯片
            XMLSlideShow slideShow = slide.getSlideShow();
            XSLFPictureData idx = slideShow.addPicture(bt2, PictureData.PictureType.PNG);
            XSLFPictureShape pictureShape = slide.createPicture(idx);
            pictureShape.setAnchor(new java.awt.Rectangle(50, 200, 500, 300));

        }
        return xmlSlideShow;
    }

}
